/**
 * 
 */
package com.appspot.myjsf2;

import java.io.IOException;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import oauth.signpost.OAuthConsumer;
import oauth.signpost.OAuthProvider;
import oauth.signpost.exception.OAuthCommunicationException;
import oauth.signpost.exception.OAuthExpectationFailedException;
import oauth.signpost.exception.OAuthMessageSignerException;
import oauth.signpost.exception.OAuthNotAuthorizedException;

/**
 * @author worker
 *
 */
public class TwitterEntryServlet extends HttpServlet{
	public void doGet(HttpServletRequest req, HttpServletResponse resp)
	throws IOException {
	System.out.println("hello from system.out");
	//resp.setContentType("text/plain");
	//resp.getWriter().println("Hello, world");
	try {
		String callbackUrl = "http://myjsf2.appspot.com/twitterCallback";
		String redirectUrl = TwitterAuther.provider.retrieveRequestToken(callbackUrl);
		OAuthConsumer consumer = TwitterAuther.consumer;
		OAuthProvider provider = TwitterAuther.provider;
		System.out.println("Request Token: " + consumer.getToken());
		System.out.println("Request Secret: " + consumer.getTokenSecret());
		resp.sendRedirect(redirectUrl);

	} catch (OAuthMessageSignerException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	} catch (OAuthNotAuthorizedException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	} catch (OAuthExpectationFailedException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	} catch (OAuthCommunicationException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
}

}
